#include "httplib.h"
#include <iostream>
#include <jsoncpp/json/json.h>
#include <fstream>
#include <string>
using std::cout;
using std::endl;
using std::cerr;
int main()
{
    httplib::Client cli("192.168.184.129",8080);
    //其响应要求时间短，我们故意设置成长时间
    cli.set_connection_timeout(5000 * 1000); // 

    // 设置读取超时（单位为毫秒）
    cli.set_read_timeout(5000 * 1000); // 

    Json::Value root;
    std::fstream fs("test.cc",std::fstream::app | std::fstream::in);
    std::string content_code;
    std::string tmp;
    while(!fs.eof())
    {
        std::getline(fs,tmp);
        content_code += tmp+ "\n";
    }
    root["code"] = content_code;
    root["input"] = 1234;
    root["CPU_limit"] = 10;
    root["Memory_limit"] = 1024*100;//100MB

    auto res = cli.Post("/compile_and_run",root.toStyledString(),"application/json;charset=utf-8");
    if (res) {
        // 打印响应状态码
        std::cout << "Status: " << res->status << std::endl;
        // 打印响应正文
        std::cout << "Response: " << res->body << std::endl;
    } else {
        std::cerr << "Error: " << httplib::to_string(res.error()) << std::endl;
    }
    std::cerr<<"错误："<<res.error()<<std::endl;
    return 0;
}


